import os

class Config:
    # 基本配置
    SECRET_KEY = os.environ.get('SECRET_KEY', 'dev')
    DEBUG = False
    TESTING = False
    
    # 数据库配置
    DATABASE = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'instance', 'm3u8_downloader.sqlite')
    
    # Redis配置
    REDIS_URL = os.environ.get('REDIS_URL', 'redis://192.168.2.8:6379/0')
    SSE_REDIS_URL = REDIS_URL
    
    # 下载配置
    DOWNLOAD_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'downloads')
    MAX_CONCURRENT_DOWNLOADS = 3
    CHUNK_SIZE = 1024 * 1024  # 1MB
    TIMEOUT = 30
    RETRY_COUNT = 3
    
    # 代理配置
    PROXY_ENABLED = False
    PROXY_URL = None
    
    # 日志配置
    LOG_LEVEL = 'INFO'
    LOG_FILE = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'logs', 'app.log')

class DevelopmentConfig(Config):
    DEBUG = True
    LOG_LEVEL = 'DEBUG'

class ProductionConfig(Config):
    # 生产环境特定配置
    SECRET_KEY = os.environ.get('SECRET_KEY')
    REDIS_URL = os.environ.get('REDIS_URL')
    SSE_REDIS_URL = os.environ.get('SSE_REDIS_URL')

class TestingConfig(Config):
    TESTING = True
    DATABASE = ':memory:'

# 配置映射
config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'testing': TestingConfig,
    'default': DevelopmentConfig
}

# 获取当前环境的配置
def get_config():
    env = os.environ.get('FLASK_ENV', 'default')
    return config[env] 